#include "file.h"

using namespace kraw;

File::File(const std::string& path, bool bundle) :
isOpen(false),
isBundle(bundle)
{
}

File::~File()
{
	if (isOpen)
		close();
}

bool File::open(const char* mode /*= "rb"*/)
{
	isOpen = true;
	return isOpen;
}

void File::close()
{
	if (isOpen) {
		isOpen = false;
	}
}

int File::read(void* buffer, int count)
{
	return 0;
}

int File::write(const void* buffer, int size, int count)
{
	return 0;
}

long File::getSize()
{
	return 0;
}

bool File::exists()
{
	return false;
}

const std::string& File::getFullPath()
{
	return fullPath;
}

std::string File::load()
{
	std::string buffer;
	if (open()) {
		int filesize = getSize();
		if (filesize > 0) {
			buffer.resize(filesize);
			read(&buffer[0], filesize);
		}
		close();
	}
	return buffer;
}

FilePath::FilePath(const std::string& path) :
value(path)
{
}

std::string FilePath::string()
{
	return value;
}

std::string FilePath::extension()
{
	size_t pos = value.find_last_of(".");
	if (pos != std::string::npos) {
		return value.substr(pos+1);
	}

	return "";
}
